﻿using MyKTV;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace HolidaysDemo1
{
    public partial class Form3 : Form
    {
        DBHelper dBHelper = new DBHelper();
        DataSet ds = new DataSet();
        public Form3()
        {
            InitializeComponent();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void Form3_Load(object sender, EventArgs e)
        {
            dBHelper.Openconnection();
            string sql = "select count,t1.teamName,t2.teamName,competitionTime,competitionPosition,score,entryPerson from ScheduleInfo inner join TeamInfo t1 on ScheduleInfo.hostTeamId = t1.id inner join TeamInfo t2 on ScheduleInfo.awayTeamId = t2.id";
            SqlDataAdapter adapter = new SqlDataAdapter(sql,dBHelper.Connection);
            adapter.Fill(ds, "ScheduleInfo");
            this.dataGridView1.DataSource = ds.Tables["ScheduleInfo"];
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ds.Tables["ScheduleInfo"].Clear();
            if (textBox1.Text.Equals(string.Empty))
            {
                MessageBox.Show("请输入查询条件");
                return;
            }
            else
            {
                string sql = "select count,t1.teamName,t2.teamName,competitionTime,competitionPosition,score,entryPerson from ScheduleInfo inner join TeamInfo t1 on ScheduleInfo.hostTeamId = t1.id inner join TeamInfo t2 on ScheduleInfo.awayTeamId = t2.id where t1.teamName like '%"+this.textBox1.Text+"%'";
                SqlDataAdapter adapter = new SqlDataAdapter(sql, dBHelper.Connection);
               int shu= adapter.Fill(ds, "ScheduleInfo");
                this.dataGridView1.DataSource = ds.Tables["ScheduleInfo"];

                if (shu==0)
                {
                    MessageBox.Show("未查询到信息");
                    return;
                }
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
